package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IUserFamilyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.UserFamilyReqVO;
import com.bjc.base.bean.response.UserFamilyVO;

/**
 * <p>
 * 用户家庭成员 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "userFamily-api", tags = { "用户家庭成员相关接口" })
public class UserFamilyController {

    @Autowired
    private IUserFamilyService userFamilyService;

	@ApiOperation("分页查询用户家庭成员")
	@GetMapping("userFamily/findPage")
	public ResultVO getUserFamilyPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			UserFamilyReqVO userFamilyReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<UserFamilyVO> userFamilyVOs = userFamilyService.getList(userFamilyReqVO);
		return ResultGenerator.getSuccess(new PageInfo<UserFamilyVO>(userFamilyVOs));
	}
	
	@ApiOperation("分页查询用户家庭成员")
	@GetMapping("userFamily/find")
	public ResultVO getUserFamilye(UserFamilyReqVO userFamilyReqVO) {
		UserFamilyVO userFamilyVO = userFamilyService.get(userFamilyReqVO);
		return ResultGenerator.getSuccess(userFamilyVO);
	}

	@ApiOperation("添加用户家庭成员")
	@PostMapping("userFamily/create")
	public ResultVO createUserFamily(@RequestBody UserFamilyReqVO userFamilyReqVOs) {
		int count = userFamilyService.insert(userFamilyReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新用户家庭成员")
	@PutMapping("userFamily/update")
	public ResultVO updateUserFamily(@RequestBody UserFamilyReqVO userFamilyReqVOs) {
		int count = userFamilyService.update(userFamilyReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除用户家庭成员")
	@DeleteMapping("userFamily/deleteList")
	public ResultVO deleteUserFamily(@ApiParam(value = "userFamily id集合") @RequestBody int[] ids) {
		int count = userFamilyService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
